package castledefense.gui.upgradePanel;

import twl.global.widget.LabelFonts;
import castledefense.data.GameData;
import castledefense.logic.units.Unit;
import de.matthiasmann.twl.Widget;
import de.matthiasmann.twl.renderer.AnimationState.StateKey;

public class UnitInfoPanel extends Widget{
	
	public static final StateKey STATE_FIRE = StateKey.get("fire");
	public static final StateKey STATE_WATER = StateKey.get("water");
	public static final StateKey STATE_EARTH = StateKey.get("earth");
	public static final StateKey STATE_AIR = StateKey.get("air");
	
	private Widget unitImage;
	private LabelFonts labelTitle;
	private LabelFonts labelDescription;
	private LabelFonts labelHealth;
	private LabelFonts labelDamage;
	private LabelFonts labelSpeed;
	
	public UnitInfoPanel() {

		setTheme("");
		
		unitImage = new Widget();
		unitImage.setTheme("elementIconTheme");
		unitImage.setSize(30, 30);
		unitImage.setPosition(15, 15);
		add(unitImage);

		labelTitle = new LabelFonts();
		labelTitle.setTheme("labelTheme");
		labelTitle.setFont("arialBold20");
		labelTitle.setPosition(62, 20);
		
		add(labelTitle);
		
		Widget line = new Widget();
		line.setTheme("fillRectBlack");
		line.setSize(159, 1);
		line.setPosition(10, 60);
		add(line);
		
		labelDescription = new LabelFonts();
		labelDescription.setTheme("labelTheme");
		labelDescription.setFont("arialItalic16");
		labelDescription.setPosition(10, 80);
		add(labelDescription);
		
		LabelFonts health = new LabelFonts("Health");
		health.setTheme("labelTheme");
		health.setFont("arialBold16");
		health.setPosition(10, 110);
		add(health);
		
		LabelFonts damage = new LabelFonts("Damage");
		damage.setTheme("labelTheme");
		damage.setFont("arialBold16");
		damage.setPosition(10, 125);
		add(damage);
		
		LabelFonts speed = new LabelFonts("Speed");
		speed.setTheme("labelTheme");
		speed.setFont("arialBold16");
		speed.setPosition(10, 140);
		add(speed);
		
		labelHealth = new LabelFonts();
		labelHealth.setTheme("labelTheme");
		labelHealth.setFont("arialBold15");
		labelHealth.setPosition(70, 110);
		add(labelHealth);
		
		labelDamage = new LabelFonts();
		labelDamage.setTheme("labelTheme");
		labelDamage.setFont("arialBold15");
		labelDamage.setPosition(70, 125);
		add(labelDamage);
		
		labelSpeed = new LabelFonts();
		labelSpeed.setTheme("labelTheme");
		labelSpeed.setFont("arialBold15");
		labelSpeed.setPosition(70, 140);
		add(labelSpeed);
		
	}
	
	public void draw(Unit unit, Widget rootPane) {
		
		if(unit.getType() == GameData.fire){
			labelTitle.setText("Fire Unit");
		}else if(unit.getType() == GameData.water){
			labelTitle.setText("Water Unit");
		}else if(unit.getType() == GameData.earth){
			labelTitle.setText("Earth Unit");
		}else if(unit.getType() == GameData.air){
			labelTitle.setText("Air Unit");
		}

		labelDescription.setText("The unit you must kill.");
		labelHealth.setText(":  " + (int)unit.getHealth() + " / " + (int)unit.getInitialHealth());
		labelDamage.setText(":  " + (int)(unit.getDamage()*1000)/1000.0);
		labelSpeed.setText(":  " + unit.getSpeed());
		
		unitImage.getAnimationState().setAnimationState(STATE_FIRE, unit.getType() == GameData.fire);
		unitImage.getAnimationState().setAnimationState(STATE_WATER, unit.getType() == GameData.water);
		unitImage.getAnimationState().setAnimationState(STATE_EARTH, unit.getType() == GameData.earth);
		unitImage.getAnimationState().setAnimationState(STATE_AIR, unit.getType() == GameData.air);
		
		if(!(rootPane.getNumChildren() == 1 && rootPane.getChild(0) == this)){
			rootPane.removeAllChildren();
			rootPane.add(this);
		}
	}

}
